package net.suncaper.demo.service;

import net.suncaper.demo.domain.Order;
import net.suncaper.demo.mapper.OrderMapper;
import net.suncaper.demo.domain.OrderExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper OrderMapper;

    @Override
    public List<Order> findOrder(String username) {
        OrderExample example=new OrderExample();

        if(username!=null&&!username.equals("")){
            example.createCriteria().andUsernameLike("%"+username+"%");
        }
        return OrderMapper.selectByExample(example);
    }

    @Override
    public List<Order> selectOrder(Order order) {
        OrderExample example=new OrderExample();
//        Long id = new Long((long)2);
//example.createCriteria().andUseridEqualTo(id);
          return OrderMapper.selectOrders(order);
//        return OrderMapper.selectByExample(example);
}
    @Override
    public void updateOrder(Order order) {

        OrderMapper.updateByPrimaryKey(order);
    }

    @Override
    public void saveOrder(Order order) {
        OrderMapper.insert(order);
    }

    @Override
    public int deleteOrderById(long orderid) { return OrderMapper.deleteByPrimaryKey(orderid); }

    @Transactional
    @Cacheable("orders")
    public Order findUserById(long orderid){ return OrderMapper.selectByPrimaryKey(orderid); }



}
